﻿using Asmodat.Abbreviate;
using Asmodat.Extensions.Collections.Generic;
using Asmodat.Extensions.Objects;
using Asmodat.IO;
using Asmodat.Types;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Asmodat_ELM
{
    public partial class Form1 : Form
    {
        private bool _IsOpen_Old = false;
        public void Peacemaker_FilesManager()
        {

            var scan = GetAllFileNames();
            var checks = new List<bool>();

            if (SelectMode == SelectModes.All)
            {
                checks = ListEx.Create(scan.Count, true);
                TCLBxFiles_ItemCheck_Igonre = true;
                TCLBxFiles.SetRange(scan.ToList<object>(), checks);
                TCLBxFiles_ItemCheck_Igonre = false;
            }
            else if(SelectMode == SelectModes.Changes)
            {
               var selected = GetChangedFileNames();
               

                for (int i = 0; i < scan.Count; i++)
                    if (selected.Contains(scan[i]))
                        checks.Add(true);
                    else
                        checks.Add(false);

                TCLBxFiles_ItemCheck_Igonre = true;
                TCLBxFiles.SetRange(scan.ToList<object>(), checks);
                TCLBxFiles_ItemCheck_Igonre = false;
            }
            else if (SelectMode == SelectModes.Selected)
            {
                for (int i = 0; i < scan.Count; i++)
                    if (SelectedFiles.Contains(scan[i]))
                        checks.Add(true);
                    else
                        checks.Add(false);

                TCLBxFiles_ItemCheck_Igonre = true;
                TCLBxFiles.SetRange(scan.ToList<object>(), checks);
                TCLBxFiles_ItemCheck_Igonre = false;
            }



            if (_serialPort.IsOpen)
            {
                TBtnUpload.Enabled = true;
            }
            else
            {
                if (Uploading && !_serialPort.IsOpen)
                    this.Upload_Stop();

                TBtnUpload.Enabled = false;
            }

            if(_IsOpen_Old != _serialPort.IsOpen)
            {
                if(_serialPort.IsOpen)
                    this.Info = "Serial Port Open";
                else
                    this.Info = "Serial Port Closed";

                _IsOpen_Old = _serialPort.IsOpen;
            }

        }

        //


    }
}
